#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 2e5 + 5;

int n, m;
string s, t;
bool check(string x, string y) {
  int len = x.size();
  rep(i, 0, len - 1) {
    if (x[i] == '2' && y[i] == '2') return false;
  }
  return true;
}
void solve() {
  if (s.size() > t.size()) swap(s, t);
  n = s.size(), m = t.size();
  int ans = n + m;
  per(len, n, 1) {
    string x = s.substr(n - len);
    string y = t.substr(0, len);
    if (check(x, y)) {
      ans = n + m - len;
      break;
    }
    x = s.substr(0, len);
    y = t.substr(m - len);
    if (check(x, y)) {
      ans = n + m - len;
      break;
    }
  }
  rep(i, 0, m - n) {
    string y = t.substr(i, n);
    if (check(s, y)) {
      ans = m;
      break;
    }
  }
  cout << ans << endl;
}

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  while (cin >> s >> t) {
    solve();
  }
  return 0;
}